# Makefile - 纯C++编译（支持.hpp头文件）

# 编译器
CXX = g++

# 编译选项
CXXFLAGS = -Wall -Wextra -std=c++11
DEBUG_FLAGS = -g
RELEASE_FLAGS = -O2 -DNDEBUG
LDFLAGS = -lpthread -lm

# 目标文件名
TARGET = cpp_my_program

# 源文件目录
SRC_DIR = src
# 头文件目录
INC_DIR = include

# 自动检测源文件（仅C++）
CPP_SOURCES = $(wildcard $(SRC_DIR)/*.cpp)

# 生成目标文件路径
CPP_OBJECTS = $(patsubst $(SRC_DIR)/%.cpp,build/%.o,$(CPP_SOURCES))
OBJECTS = $(CPP_OBJECTS)

# 默认目标
all: debug

# 调试模式
debug: CXXFLAGS += $(DEBUG_FLAGS)
debug: $(TARGET)

# 发布模式
release: CXXFLAGS += $(RELEASE_FLAGS)
release: $(TARGET)

# 链接使用C++编译器
$(TARGET): $(OBJECTS)
	$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)

# C++源文件编译规则
build/%.o: $(SRC_DIR)/%.cpp
	@mkdir -p $(dir $@)
	$(CXX) $(CXXFLAGS) -I$(INC_DIR) -c $< -o $@

# 清理生成的文件
clean:
	rm -rf build $(TARGET)

# 重新构建
rebuild: clean all

# 帮助信息
help:
	@echo "Makefile usage:"
	@echo "  make debug     - Build the project in debug mode."
	@echo "  make release   - Build the project in release mode."
	@echo "  make clean     - Clean all generated files."
	@echo "  make rebuild   - Clean and rebuild the project."
	@echo "  make help      - Show this help message."